Maybe Type in Odin

Maybe type is a special union in Odin. Variables can either have no value or some value.

The signature of Maybe type uses parametric polymorphism.

  Maybe :: union($T: typeid) {
      T,
  }

It is very similar to Option<T> in Rust or Maybe a in Haskell. Its usage is also similar. We can use variable.? to unpack the value.

  time: Maybe(int)
  time = 5
  
  if time_val, time_val_ok := time.?; time_val_ok {
      // use time_val here
  }

Date: 2026-07-17 Fri